package com.gogowan.agroenterprise.newview;

import android.app.ProgressDialog;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.contorl.RetrofitUtil.GsonUtil;
import com.gogowan.agroenterprise.contorl.RetrofitUtil.JSON_Tool;
import com.gogowan.agroenterprise.contorl.RetrofitUtil.MyRetrofit;
import com.gogowan.agroenterprise.model.DealerUnConfirmRequest;
import com.gogowan.agroenterprise.model.DealerUnConfirmResult;
import com.gogowan.agroenterprise.model.OutStore;
import com.gogowan.agroenterprise.widget.adapter.Base_Adapater;

import java.util.ArrayList;
import java.util.List;

public class NewInStorageActivityTow extends BaseListView {
    private ProgressDialog progressDialog;
    private List<OutStore> OutInfo=new ArrayList<>();
    private Base_Adapater adapter;
    @Override
    protected void InitValue() {

    }

    @Override
    protected void InitView() {
        adapter=new Base_Adapater(this,OutInfo);
        adapter.setOnItemListener(new Base_Adapater.OnItemListener() {
            @Override
            public String ItemStr(int position) {
                return "单号: "+OutInfo.get(position).getOutStorageNO()
                        +"\n销售日期: "+OutInfo.get(position).getSellDate();
            }
        });
        getListView().setAdapter(adapter);
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent(NewInStorageActivityTow.this,NewInStorageActivityTowInforMation.class);
                intent.putExtra("bean",OutInfo.get(position));
                startActivity(intent);
            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        QueryHttp();
    }

    private void QueryHttp() {
        DealerUnConfirmRequest request=new DealerUnConfirmRequest();
        progressDialog = ProgressDialog.show(this,
                getString(R.string.alert_title),
                getString(R.string.alert_message), true, false);
//        request.setDealerId(getLogInfo().getEnterpriseinfo().getDealerId());
        Http(request, "", progressDialog,new RetrofitHttpListener() {
            @Override
            public void OnJson(String str) {
                DealerUnConfirmResult result= GsonUtil.GsonToBean(str,DealerUnConfirmResult.class);
                showToast(result.getResultinfo());
                OutInfo.clear();
                if (result.getResult()>0){
                    OutInfo.addAll(result.getOutInfo());
                }
                adapter.notifyDataSetChanged();
            }
        });
    }
}
